﻿/*
   Copyright 2012 University of Southampton

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using uk.ac.soton.ses.DAL;

namespace uk.ac.soton.ses
{
    [XmlRoot("experimentmetadata")]
    public class ExperimentMetadataAndHistory
    {
        //Fields
        private ExperimentBO _experiment;

        //We will set the following fields with blank values so the XML file makes sense if it is serialized
        private List<ExperimentDataFileBO> _experimentDataFiles = new List<ExperimentDataFileBO>();
        private ExperimentHistory _history = new ExperimentHistory();

        //Properties
        [XmlElement("experiment")]
        public ExperimentBO Experiment { get { return _experiment; } set { _experiment = value; } }

        [XmlArray("experimentdatafiles")]
        [XmlArrayItem("experimentdatafile")]
        public List<ExperimentDataFileBO> ExperimentDataFiles { get { return _experimentDataFiles; } set { _experimentDataFiles = value; } }

        [XmlElement("history")]
        public ExperimentHistory History { get { return _history; } set { _history = value; } }
    }
    public class ExperimentHistory
    {
        private List<ExperimentHistoryEntry> _experimentHistoryEntries = new List<ExperimentHistoryEntry>();
        private List<ExperimentDataFileHistory> _experimentDataFilesHistory = new List<ExperimentDataFileHistory>();

        [XmlArray("experiment")]
        [XmlArrayItem("historyentry")]
        public List<ExperimentHistoryEntry> ExperimentHistoryEntries { get { return _experimentHistoryEntries; } set { _experimentHistoryEntries=value;} }

        [XmlArray("experimentdatafiles")]
        [XmlArrayItem("experimentdatafile")]
        public List<ExperimentDataFileHistory> ExperimentDataFilesHistory { get { return _experimentDataFilesHistory; } set { _experimentDataFilesHistory = value; } }
    }
    public class ExperimentHistoryEntry
    {
        [XmlAttribute("action")]
        public ExperimentMetadataAction Action { get; set; }

        [XmlAttribute("timestamp")]
        public DateTime TimeStamp { get; set; }

        [XmlElement("experiment")]
        public ExperimentBO Experiment { get; set; }
    }
    public class ExperimentDataFileHistory
    {
        [XmlAttribute("experimentdatafileid")]
        public int ID { get; set; }

        [XmlArray("experimentdatafilehistory")]
        [XmlArrayItem("historyentry")]
        public List<ExperimentDataFileHistoryEntry> ExperimentDataFileHistoryEntries { get; set; }
    }
    public class ExperimentDataFileHistoryEntry
    {
        [XmlAttribute("action")]
        public ExperimentMetadataAction Action { get; set; }

        [XmlAttribute("timestamp")]
        public DateTime TimeStamp { get; set; }

        [XmlElement("experimentdatafile")]
        public ExperimentDataFileBO ExperimentDataFile { get; set; }
    }
    public enum ExperimentMetadataAction
    {
        Updated,
        Deleted
    }
}
